package com.yanqu.road.server.cmd.palace;


import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.estatewar.EstateWarProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.palace.CrossPalaceActivity;
import com.yanqu.road.server.manager.palace.CrossPalaceActivityMgr;
import com.yanqu.road.server.protocol.Protocol;

import java.math.BigInteger;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Cmd(code = Protocol.C_PALACE_PLAYER_ABILITY_SYNC, desc = "玩家实力同步")
public class CrossPalacePlayerAbilitySyncCmd extends CrossCommand {
    private int activityId;
    private Map<Long, BigInteger> abilityMap = new ConcurrentHashMap<>();

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        EstateWarProto.PalacePlayerAbilitySyncMsg reqMsg = EstateWarProto.PalacePlayerAbilitySyncMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        if(reqMsg.getDataListCount() > 0){
            for(EstateWarProto.PalacePlayerAbilityTempMsg tempMsg : reqMsg.getDataListList()){
                abilityMap.put(tempMsg.getUserId(), new BigInteger(tempMsg.getAbility()));
            }
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossPalaceActivity crossPalaceActivity = CrossPalaceActivityMgr.getCrossPalaceActivity(activityId);
        if(null != crossPalaceActivity){
            if(abilityMap.size() > 0) {
                crossPalaceActivity.syncAbility(abilityMap);
            }
        }
    }

    @Override
    public void sendData() {

    }
}
